
const shellUtil = require('../../common/utils/shellUtil');
const EnvContext = require('../../common/context/EnvContext');
const { createPackage } = require('../../core/pluginSetupService/createPackage');
const { installPackage } = require('../../core/pluginSetupService/installPackage');
const { doRunFusionPlugin } = require('./processor/doRunFusionPlugin')
const { doRunHeadlessPlugin } = require('./processor/doRunHeadlessPlugin')
const { doRunListPlugin } = require('./processor/doRunListPlugin')
const { doRunStandalonePlugin } = require('./processor/doRunStandalonePlugin')
const { doStatisticsAnalyse } = require('./processor/doStatisticsAnalyse')
const { showMain } = require('../winService/baseWinService/showMain')






exports.runPlugin = function (request) {
    /*
    request定义来自pluginFeatureInfo.cmdInfo
    mode:
    - headless: 无头模式，用于执行命令行等无界面脚本，脚本本身不支持常驻
    - standalone: 独立模式，用于运行完全独立的应用，界面完全由用户绘制，包括标题栏、窗口管理
    - fusion: 融合模式，其头部包含有全局搜索栏，下方挂在页面，与独立模式区别在于窗口管理、标题栏管理等
    - list: 列表模式，和融合模式类似，其头部包含全局搜索栏，与其不同的是下方挂在的是列表，由用户preload脚本定义逻辑
    */
    const mode = request.plugin.cmdInfo.featureInfo.mode
    if (mode == "headless") {
        doRunHeadlessPlugin(request)
    } else if (mode == "standalone") {
        doRunStandalonePlugin(request)
    } else if (mode == "list") {
        showMain()
        doRunListPlugin(request)
    } else if (mode == "fusion") {
        showMain()
        doRunFusionPlugin(request)
    }

    // 数据采集
    doStatisticsAnalyse(request)
}




function runPluginByFunction(request, event) {
    const action = request.action
    if (action == "createPackage") {
        createPackage(request, event)
    } else if (action == "setupPackage") {
        installPackage(request, event)
    }

}